import { Component, OnInit } from '@angular/core';

declare var form: any;

@Component({
  templateUrl: './data.dictionary.html'
})
export class DataDictionaryComponent implements OnInit {

  fs: any = null;
  metadataDic: any = null;
  selectNode: any;

  constructor() {
    this.fs = new form.FormSideTreeService('dictionary', {
      orderObject: { order: 0 },
      keyField: 'guid',
      randomFields: ['guid'],
      pageSize: 1000,
      foreignKey: 'dicName'
    });

    this.metadataDic = new form.DictionaryService('f_dictionary_directory');
    this.metadataDic.loadAll();
  }

  addRow() {
    if (this.selectNode && this.selectNode._isLeaf === true) {
      this.fs.addRow();
    }
  }

  loadDataEx(node: any) {
    if (node._isLeaf === true) {
      this.fs.loadDataEx(node.key);
    } else {
      this.fs.datas = [];
    }
    this.selectNode = node;
  }

  ngOnInit(): void {
  }
}
